import { Controller, Get, Query } from '@nestjs/common';
import { ChatRoomService } from './chat-room.service';

import { GetUserInfo, RequrieLogin } from 'src/cu-dec';

@Controller('chat-room')
@RequrieLogin()
export class ChatRoomController {
  constructor(private readonly chatRoomService: ChatRoomService) {}

  @Get('createOne')
  create(
    @Query('friendId') friendId: number,
    @GetUserInfo('id') userId: number,
  ) {
    return this.chatRoomService.createChatOne(+friendId, +userId);
  }

  @Get('createGroup')
  createGroup(@Query('name') name: string, @GetUserInfo('id') id: number) {
    return this.chatRoomService.createChatGroup(name, +id);
  }

  // 聊天列表
  @Get('getChatList')
  getChatList(@GetUserInfo('id') id: number) {
    return this.chatRoomService.getChatList(+id);
  }

  // 获取群聊用户
  @Get('getGroupUser')
  getGroupUser(@Query('groupId') groupId: number) {
    return this.chatRoomService.getGroupUser(+groupId);
  }

  // 获取群聊信息
  @Get('getGroupInfo')
  getGroupInfo(@Query('groupId') groupId: number) {
    return this.chatRoomService.getGroupInfo(+groupId);
  }

  // 加入群聊
  @Get('joinGroup')
  joinGroup(@Query('groupId') groupId: number, @GetUserInfo('id') id: number) {
    return this.chatRoomService.joinGroup(+groupId, +id);
  }

  // 退出群聊
  @Get('quitGroup')
  quitGroup(@Query('groupId') groupId: number, @GetUserInfo('id') id: number) {
    return this.chatRoomService.quitGroup(+groupId, +id);
  }

  // 搜索群聊
  @Get('searchGroup')
  searchGroup(@Query('name') keyword: string) {
    return this.chatRoomService.searchGroup(keyword);
  }

  // 获取群聊列表
  @Get('getGroupList')
  getGroupList(@GetUserInfo('id') id: number) {
    return this.chatRoomService.getGroupList(+id);
  }
}
